package com.zoshine.zzg.controller;

import com.github.pagehelper.PageInfo;
import com.zoshine.zzg.annotation.DisableLoginCheck;
import com.zoshine.zzg.base.BaseResponse;
import com.zoshine.zzg.pojo.PrisonerAccount;
import com.zoshine.zzg.pojo.PrisonerCapitalFlow;
import com.zoshine.zzg.pojo.pojostatus.PrisonerCapitalFlowStatus;
import com.zoshine.zzg.respons.AppResponse;
import com.zoshine.zzg.service.PrisonerAccountService;
import com.zoshine.zzg.service.PrisonerCapitalFlowService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**犯人资金流动记录控制层
 * @author 田沛凌
 * @time 2017/8/18 11:32
 */
@RestController
@RequestMapping(value = "prisonerCapitalFlow", method = RequestMethod.POST)
public class PrisonerCapitalFlowController extends BaseController{
    private PrisonerCapitalFlowService prisonerCapitalFlowService;
    private PrisonerAccountService prisonerAccountService;
    @Autowired
    public void setPrisonerCapitalFlowService(PrisonerCapitalFlowService prisonerCapitalFlowService) {
        this.prisonerCapitalFlowService = prisonerCapitalFlowService;
    }
    @Autowired
    public void setPrisonerAccountService(PrisonerAccountService prisonerAccountService) {
        this.prisonerAccountService = prisonerAccountService;
    }

    /**
     * 新增犯人资金流动记录
     * @param prisonerCapitalFlow;
     */
    @RequestMapping("addPrisonerCapitalFlow")
    public BaseResponse addPrisonerCapitalFlow(PrisonerCapitalFlow prisonerCapitalFlow){
        PrisonerAccount prisonerAccount = prisonerAccountService.get(prisonerCapitalFlow.getPrisonerId());
        prisonerCapitalFlow.setBankCard(prisonerAccount.getBankCard());
        prisonerCapitalFlow.setStatus(PrisonerCapitalFlowStatus.DELIVERY_BANK.getValue());
        prisonerCapitalFlowService.add(prisonerCapitalFlow);
        return AppResponse.OK;
    }
    /**
     * 获取犯人资金流动记录
     * @param id 犯人资金流动记录ID
     */
    @RequestMapping("getPrisonerCapitalFlow")
    public BaseResponse getPrisonerCapitalFlow(Long id){
        PrisonerCapitalFlow prisonerCapitalFlow = prisonerCapitalFlowService.get(id);
        return new AppResponse(prisonerCapitalFlow);
    }
    /**
     * 查询犯人资金流动记录(分页)
     * @param prisonerCapitalFlow；
     * @return 犯人资金流动记录集合
     */
    @DisableLoginCheck
    @RequestMapping("pagePrisonerCapitalFlow")
    public BaseResponse pagePrisonerCapitalFlow(PrisonerCapitalFlow prisonerCapitalFlow){
        List<PrisonerCapitalFlow> list = prisonerCapitalFlowService.list(prisonerCapitalFlow);
        return new AppResponse(new PageInfo<>(list));
    }
    /**
     * 删除犯人资金流动记录；
     * @param id 犯人资金流动记录ID
     */
    @RequestMapping("delPrisonerCapitalFlow")
    public BaseResponse delPrisonerCapitalFlow(Long id){
        prisonerCapitalFlowService.del(id);
        return AppResponse.OK;
    }
    /**
     * 修改犯人资金流动记录
     * @param prisonerCapitalFlow；
     */
    @RequestMapping("editPrisonerCapitalFlow")
    public BaseResponse editPrisonerCapitalFlow(PrisonerCapitalFlow prisonerCapitalFlow){
        prisonerCapitalFlowService.edit(prisonerCapitalFlow);
        return AppResponse.OK;
    }
}
